from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
import os


# 用户表扩展
class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    male = models.BooleanField(default=False)
    avatar = models.ImageField(upload_to='', default=os.path.join("uploadfiles", "nonepic.jpg"))

    def __str__(self):
        return self.user.username

class Test(models.Model):
    text = models.CharField(max_length=200)

# 博客部分
class Post(models.Model):
    title = models.CharField(max_length=200)
    people = models.CharField(max_length=200, default='')
    keyword = models.CharField(max_length=200, default='')
    picture = models.CharField(max_length=500, default='')
    body = models.TextField()
    source = models.TextField(max_length=20, default='')
    pub_date = models.DateTimeField(default=timezone.now)
    likes = models.IntegerField(default=0)
    enabled = models.BooleanField(default=False)

    class Meta:
        ordering = ('-pub_date',)

    def __str__(self):
        return self.title


# 评论部分
class comments(models.Model):
    nickname = models.CharField(max_length=10, default='不愿透露身份的神秘人')
    post_id = models.CharField(max_length=20)
    message = models.TextField(null=False)
    pub_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.message


# 收藏部分
class collect(models.Model):
    nickname = models.CharField(max_length=10)
    post_id = models.CharField(max_length=20)

    def __str__(self):
        return self.post_id


# 视频部分
class movie(models.Model):
    title = models.CharField(max_length=200)
    keyword = models.CharField(max_length=200, default='')
    source = models.TextField(max_length=200, default='')
    pub_date = models.DateTimeField(default=timezone.now)

    class Meta:
        ordering = ('-pub_date',)

    def __str__(self):
        return self.title


class Mood(models.Model):
    status = models.CharField(max_length=10, null=False)

    def __str__(self):
        return self.status


class Wish(models.Model):
    mood = models.ForeignKey('Mood', on_delete=models.CASCADE)
    nickname = models.CharField(max_length=10, default='不愿透漏身份的神秘人')
    message = models.TextField(null=False)
    pub_time = models.DateTimeField(auto_now=True)
    enabled = models.BooleanField(default=True)

    def __str__(self):
        return self.message
